<?php
/*==========================================================================*\
| AGRIVIET - CONTENT MANAGERMENT SYSTEM						
\*==========================================================================*/

if(!session_id()) session_start(); 
if (isset($_POST['butSub'])) {
	$username = db_prepare_input($HTTP_POST_VARS['txtUser']);
	$password = db_prepare_input($HTTP_POST_VARS['txtPwd']);
	if ($username=="")
	{
	$username=$_POST['txtUser'];
	$password=$_POST['txtPwd'];
	}
	ECHO "xxxxxxxxxxxx".$username;
	$check_query=mysql_query("select * from administrators where user='".$username."'");
	 if (mysql_num_rows($check_query) == 1) {
          $check = mysql_fetch_object($check_query);
		  if (validate_password($password, $check->password)) {
		  	$log=$username;
			session_register("admin");
			$_SESSION['admin']=$user;
		    echo "<script>window.location='index.php'</script>";
		    } else {
			$err=" Error: Invalid administrator login attempt.";
			}
		  }// 
    } 
?>

<br />
<?
if ($err!='')
{
	echo '<table width="274" align="center"><tr><td><div class="red">'.$err.'</div></td></tr></table>';
}
?>
<form method="post" name="FormLoaiSP">
<table width="161" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#D5E2FF">
  <tr>
    <td width="100%" height="20" class="xtitle">Administrator Login</td>
  </tr>
  <tr>
    <td width="100%" align="center">
    <table border="0" cellpadding="4" bordercolor="#111111" width="267" id="AutoNumber2" cellspacing="0">
      <tr>
        <td width="32%" align="right">Username:</td>
        <td width="57%" align="left">
		
		<input type="text" name="txtUser" size="20" style="width:90%"></td>
      </tr>
      <tr>
        <td width="32%" align="right">Password:</td>
        <td width="57%" align="left">

		<input type="password" name="txtPwd" size="20" style="width:90%"></td>
      </tr>
      <tr>
        <td width="37%">
		<p align="center"></td>
        <td width="57%" align="left"><font face="Script">
          <input type="submit" name="butSub" value="Login" class="button">
        </font></td>
      </tr>
    </table>
    </td>
  </tr>
</table></form><br>
